function onPropertyChangeFcn(obj,model, event)

% This file is part of CISNE.
%
%     CISNE is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     any later version.
%
%     CISNE is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with CISNE.  If not, see <http://www.gnu.org/licenses/>.

% Copyright 2011. Jose Maria Garcia-Valdecasas Bernal

node=obj.m_tree.getSelectedNodes();
if ~isempty(node)
    node=node(1);
    parent=node.getParent();
else
    parent=[];
end

if ~isempty(parent)
    val=parent.getValue();
    val=char(val(2));
    if strcmp(val,'INPUT')
        handles=guidata(obj.m_figure);
        node=obj.currentNode;
        
        %how to handle changes in input grids
        switch char(event.getPropertyName())
            case 'File'
                filePath = char(event.getNewValue());
                if ~isempty(filePath)
                    handles.DisplayWidget.addInputGrid(node,filePath);
                end
            case 'Style'
                if ~isempty(handles.DisplayWidget.getMethod(node));
                    if strcmp(event.getNewValue(),'image')
                        handles.DisplayWidget.setMethod(node,'image');
                    elseif strcmp(event.getNewValue(),'contourlines')
                        handles.DisplayWidget.setMethod(node,'contour');
                    end
                    
                    if ~isempty(handles.DisplayWidget.getData(node))
                        handles.DisplayWidget.drawIGrid(node);
                    end
                end
            case 'Opacity'
                if ~isempty(handles.DisplayWidget.getData(node))
                    n=event.getNewValue();
                    n=n/100;
                    if n>=0 && n<=1
                        alpha(handles.DisplayWidget.getHandle(node),n);
                        
                    end
                end
            case 'Flip'
                if event.getNewValue() %if true
                    % +2 to filetype if set
                else
                    % -2 to filetype if set
                end
                data=handles.DisplayWidget.getData(node);
                if ~isempty(data)
                    switch node
                        case {'BATHYMETRY', 'VEGETATION', 'FRICTION'}
                    handles.DisplayWidget.setData(node,flipud(data));
                        otherwise
                            data(:,:,1)=flipud(data(:,:,1));
                            data(:,:,2)=flipud(data(:,:,2));
                            handles.DisplayWidget.setData(node,data);
                    end
                    handles.DisplayWidget.drawIGrid(node);
                    
                end
            case 'Swap'
                data=handles.DisplayWidget.getData(node);
                if ~isempty(data)
                    handles.DisplayWidget.setData(node,data.*(-1));
                    handles.DisplayWidget.drawIGrid(node);
                end
            case {'Xmin','Ymin','Nx','Ny','X Step','Y Step'}
                saveGridData(obj,node);
                handles.DisplayWidget.drawIGrid(node);
                
        end
           
    
    elseif strcmp(val,'CPOINTS')
        grid=node.getValue();
        grid=char(grid(2));
        saveGridData(obj,grid);
        obj.updateDisplay(node);
        
    else
        type=node.getValue();
        type=char(type(2));
        if ~isempty(strfind(type,'cMain'))|~isempty(strfind(type,'cNest'))
            switch char(event.getPropertyName())
                case {'X0','Y0','X Length','Y Length','Angle','Dx','Dy'}
                %represent changes in Display Widget for comp. grids.
                %prop = model.getProperty(event.getPropertyName());
                %prop.setBackground(java.awt.Color.red)
                %prop.setValue(event.getNewValue());
                %model.refresh();
                grid=node.getValue();
                grid=char(grid(2));
                saveGridData(obj,grid);
                obj.updateDisplay(node);
                %if data is not valid show in red, else show in white
            end
        end
    end
end
